package com.zx.idc.backend.gui.api.ws.services.handler.strategy.command.commandtype.infosecurityquery.illegalmanagementexecutionrecord;

import com.zx.idc.backend.gui.api.commom.entity.CommandModel;
import com.zx.idc.backend.gui.api.management.infosecurity.violationwebsite.common.service.CommandRecordService;
import com.zx.idc.backend.gui.api.ws.services.handler.strategy.command.base.CommandOperating;
import com.zx.idc.backend.gui.api.ws.services.handler.strategy.command.base.SubCommandHandler;
import com.zx.idc.backend.gui.api.ws.services.handler.strategy.entity.Option;
import com.zx.idc.xml.entity.CommandRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import static com.zx.idc.common.attributes.SchemaFileNameAttributes.ILLEGAL_INFO_EXECUTION_RECORD;

/**
 * Created by hasee on 2019/3/1.
 * 违法管理指令执行记录指令 11.20
 */
@Component
@Transactional(rollbackFor = Exception.class)
public class IllegalManagementExecutionRecordImpl extends CommandOperating<CommandRecord> implements SubCommandHandler {

    private String schemaPath = getSchemaFilePath(ILLEGAL_INFO_EXECUTION_RECORD);

    @Autowired
    private CommandRecordService commandRecordService;

    /**
     * 匹配方法
     *
     * @param xmlData
     * @return
     */
    @Override
    public boolean isMatch(String xmlData) {
        CommandRecord commandRecord = xml2Bean(xmlData, getFirstGenericClass(), schemaPath);
        return !ObjectUtils.isEmpty(commandRecord);
    }

    /**
     * 执行方法
     *
     * @param xmlData
     * @param commandModel
     * @return
     */
    @Override
    public String execute(String xmlData, CommandModel commandModel) {
        return receiveCommand(xmlData, commandModel, schemaPath);
    }

    /**
     * 覆盖该方法执行指令
     *
     * @param commandRecord 实体bean
     * @param commandModel  指令mode
     */
    @Override
    public void task(CommandRecord commandRecord, CommandModel commandModel) {
        commandRecordService.commandRecord(commandRecord, commandModel);
    }
}
